import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== global declare
const { $Lazy, $fn, $http, globalConfig } = window
const { COVIDUrl } = globalConfig
// ===================================================================== Lazy
const Page 	 		= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		formData : [
			{ label: '项目名称',			name: 'ConvidProjectName', 		half:true,		br:true  },
			{ label: '报告单前缀',		name: 'ConvidReportPrefix', 	half:true,		br:true, },
			{ label: '报告单模板',		name: 'ConvidRePortTmpId', 		half:true,		br:true, },
			{ label: '新冠价格：单采',	name: 'ConvidSinglePrice', 		width:'25%',	br:true, p:'请输入单采价格', },
			{ label: '混采',			name: 'ConvidMultiplePrice', 	width:'25%',	p:'请输入混采价格', }
		]
	}
	
	componentDidMount(){
		this.getValue()
	}
	
	getValue = () => {
		$http.pull(null,COVIDUrl+'settings/query',{ param:{page_num:1000,page:1 }}).then(data=>{
			let formValue = this.formRef.getValue()
			if($fn.hasArray(data)){
				data.map(v=> formValue[v.settingsCode] = v.settingsValue)
			}
			this.formRef.setValue(formValue)
		})
	}
	
	render(){
		return (
			<>
				<Page title='系统设置'>
					<div className='ex pt20 mlr20 fv'>
						{ SubmitForm.call(this,{ okText:'确定', btnSize:'large', noEsc:true, hideButton:false, scroll:true, labelWidth:'s7', enter: false,
							onSubmit: param =>{
								$http.submit(null,COVIDUrl+'settings/update', { param }).then(data=>{
									$fn.msg.success('设置成功')
									this.getValue()
								})
								
							}
						}) }
					</div>
				</Page>
			</>
		)
	}
}

export default Index